import { Component, OnInit, Input } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd/message';
import { FinanceDrawbackService } from '../../finance-drawback/finance-drawback.service';

@Component({
  selector: 'app-flow-record',
  templateUrl: './flow-record.component.html',
  styleUrls: ['./flow-record.component.scss']
})
export class FlowRecordComponent implements OnInit {
  @Input() changeNo: any;

  // Modal
  isRecordVisible: boolean = false;
  modalTableParams: any = {
    loading:  false,
    page: 1,
    pageSize: 10,
    total: 0
  };
  modalTableData: any = [];

  constructor(
    private message: NzMessageService,
    private services: FinanceDrawbackService
  ) {}

  ngOnInit(): void {}

  async loadModalTable() {
    try {
      this.modalTableParams.loading = true;
      const res: any = await this.services.getDrawbackFlow({ changeNo: this.changeNo });
      this.modalTableParams.loading = false;

      if (res.code == 0) {
        this.modalTableData = res.data;
      } else {
        this.message.error(res.message || '流水记录获取失败');
      }
    } catch (error: any) {
      this.modalTableParams.loading = false;
      this.message.error(error);
    }
  }

  handleCancel() {
    this.modalTableData = [];
    this.isRecordVisible = false;
  }

  /**
   * 当前页码改变时的回调函数
   * @param index
   */
   onPageIndexChange(index: number) {
    this.modalTableParams.page = index;
    this.loadModalTable();
  }
  /**
   * 每页条数改变的回调
   * @param sizeNum
   */
  onPageSizeChange(sizeNum: number) {
    this.modalTableParams.pageSize = sizeNum;
    this.loadModalTable();
  }
}
